package com.lenin.metro.client;

import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.lenin.metro.shared.MapCoordinates;
import com.lenin.metro.shared.MapObject;
import com.lenin.metro.shared.ProjectionPoint;

public class MapObjectPanel extends AbsolutePanel {
	
	private MapObject mapObject;
	
	private int width;
	private int height;
	
	private String id;
	
	
	public MapObjectPanel(MapObject mapObject) {
		
		this.mapObject = mapObject;
		
		setStyleName("mapObjectPanel");
		getElement().getStyle().setOverflow(Overflow.VISIBLE);
		
		long lat = mapObject.getCoordinates().getLatitude();
		long lng = mapObject.getCoordinates().getLongitude();
		id = "id"+lat+"_"+lng;
		
		getElement().setId(id);
		
	}

	
	public int getWidth() {
		return width;
	}


	public void setWidth(int width) {
		this.width = width;
		setWidth(width+"px");
	}


	public int getHeight() {
		return height;
	}


	public void setHeight(int height) {
		this.height = height;
		setHeight(height+"px");
	}
	
	
	public void build() {
		
		ProjectionPoint bottomRight = mapObject.getRectBottomRight();
		
		long width = bottomRight.getX();
		long height = bottomRight.getY();
		
		setWidth((int)width);
		setHeight((int)height);
		
		String imageCss = mapObject.getImageCss();
		if(imageCss != null) {
			addStyleName(imageCss);
		}
		
		//System.out.println("ObjPanel ("+width+"x"+height+")");
		
	}
	
	
	public MapObject getMapObject() {
		
		return mapObject;
	
	}
	
	public MapCoordinates getMapCoordinates() {
		
		MapCoordinates coords = null;
		
		if(mapObject != null) {
			coords = mapObject.getCoordinates();
		}
		
		return coords;
		
	}
	
	
	public String getObjectKey() {
		
		return mapObject.getKey();
		
	}
	
	
	

}
